<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <title>sgeqp3.f</title>
 <meta name="generator" content="emacs 21.3.1; htmlfontify 0.20">
<style type="text/css"><!-- 
body { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.default   { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.default a { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
span.string   { color: rgb(188, 143, 143);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.string a { color: rgb(188, 143, 143);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
span.comment   { color: rgb(178, 34, 34);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.comment a { color: rgb(178, 34, 34);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
 --></style>

 </head>
  <body>

<pre>
      SUBROUTINE <a name="SGEQP3.1"></a><a href="sgeqp3.f.html#SGEQP3.1">SGEQP3</a>( M, N, A, LDA, JPVT, TAU, WORK, LWORK, INFO )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  -- LAPACK routine (version 3.1) --
</span><span class="comment">*</span><span class="comment">     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
</span><span class="comment">*</span><span class="comment">     November 2006
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     .. Scalar Arguments ..
</span>      INTEGER            INFO, LDA, LWORK, M, N
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Array Arguments ..
</span>      INTEGER            JPVT( * )
      REAL               A( LDA, * ), TAU( * ), WORK( * )
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Purpose
</span><span class="comment">*</span><span class="comment">  =======
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  <a name="SGEQP3.18"></a><a href="sgeqp3.f.html#SGEQP3.1">SGEQP3</a> computes a QR factorization with column pivoting of a
</span><span class="comment">*</span><span class="comment">  matrix A:  A*P = Q*R  using Level 3 BLAS.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Arguments
</span><span class="comment">*</span><span class="comment">  =========
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  M       (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The number of rows of the matrix A. M &gt;= 0.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  N       (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The number of columns of the matrix A.  N &gt;= 0.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  A       (input/output) REAL array, dimension (LDA,N)
</span><span class="comment">*</span><span class="comment">          On entry, the M-by-N matrix A.
</span><span class="comment">*</span><span class="comment">          On exit, the upper triangle of the array contains the
</span><span class="comment">*</span><span class="comment">          min(M,N)-by-N upper trapezoidal matrix R; the elements below
</span><span class="comment">*</span><span class="comment">          the diagonal, together with the array TAU, represent the
</span><span class="comment">*</span><span class="comment">          orthogonal matrix Q as a product of min(M,N) elementary
</span><span class="comment">*</span><span class="comment">          reflectors.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  LDA     (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The leading dimension of the array A. LDA &gt;= max(1,M).
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  JPVT    (input/output) INTEGER array, dimension (N)
</span><span class="comment">*</span><span class="comment">          On entry, if JPVT(J).ne.0, the J-th column of A is permuted
</span><span class="comment">*</span><span class="comment">          to the front of A*P (a leading column); if JPVT(J)=0,
</span><span class="comment">*</span><span class="comment">          the J-th column of A is a free column.
</span><span class="comment">*</span><span class="comment">          On exit, if JPVT(J)=K, then the J-th column of A*P was the
</span><span class="comment">*</span><span class="comment">          the K-th column of A.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  TAU     (output) REAL array, dimension (min(M,N))
</span><span class="comment">*</span><span class="comment">          The scalar factors of the elementary reflectors.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  WORK    (workspace/output) REAL array, dimension (MAX(1,LWORK))
</span><span class="comment">*</span><span class="comment">          On exit, if INFO=0, WORK(1) returns the optimal LWORK.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  LWORK   (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The dimension of the array WORK. LWORK &gt;= 3*N+1.
</span><span class="comment">*</span><span class="comment">          For optimal performance LWORK &gt;= 2*N+( N+1 )*NB, where NB
</span><span class="comment">*</span><span class="comment">          is the optimal blocksize.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">          If LWORK = -1, then a workspace query is assumed; the routine
</span><span class="comment">*</span><span class="comment">          only calculates the optimal size of the WORK array, returns
</span><span class="comment">*</span><span class="comment">          this value as the first entry of the WORK array, and no error
</span><span class="comment">*</span><span class="comment">          message related to LWORK is issued by <a name="XERBLA.62"></a><a href="xerbla.f.html#XERBLA.1">XERBLA</a>.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  INFO    (output) INTEGER
</span><span class="comment">*</span><span class="comment">          = 0: successful exit.
</span><span class="comment">*</span><span class="comment">          &lt; 0: if INFO = -i, the i-th argument had an illegal value.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Further Details
</span><span class="comment">*</span><span class="comment">  ===============
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  The matrix Q is represented as a product of elementary reflectors
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Q = H(1) H(2) . . . H(k), where k = min(m,n).
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Each H(i) has the form
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     H(i) = I - tau * v * v'
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  where tau is a real/complex scalar, and v is a real/complex vector
</span><span class="comment">*</span><span class="comment">  with v(1:i-1) = 0 and v(i) = 1; v(i+1:m) is stored on exit in
</span><span class="comment">*</span><span class="comment">  A(i+1:m,i), and tau in TAU(i).
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Based on contributions by
</span><span class="comment">*</span><span class="comment">    G. Quintana-Orti, Depto. de Informatica, Universidad Jaime I, Spain
</span><span class="comment">*</span><span class="comment">    X. Sun, Computer Science Dept., Duke University, USA
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  =====================================================================
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     .. Parameters ..
</span>      INTEGER            INB, INBMIN, IXOVER
      PARAMETER          ( INB = 1, INBMIN = 2, IXOVER = 3 )
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Local Scalars ..
</span>      LOGICAL            LQUERY
      INTEGER            FJB, IWS, J, JB, LWKOPT, MINMN, MINWS, NA, NB,
     $                   NBMIN, NFXD, NX, SM, SMINMN, SN, TOPBMN
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. External Subroutines ..
</span>      EXTERNAL           <a name="SGEQRF.99"></a><a href="sgeqrf.f.html#SGEQRF.1">SGEQRF</a>, <a name="SLAQP2.99"></a><a href="slaqp2.f.html#SLAQP2.1">SLAQP2</a>, <a name="SLAQPS.99"></a><a href="slaqps.f.html#SLAQPS.1">SLAQPS</a>, <a name="SORMQR.99"></a><a href="sormqr.f.html#SORMQR.1">SORMQR</a>, SSWAP, <a name="XERBLA.99"></a><a href="xerbla.f.html#XERBLA.1">XERBLA</a>
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. External Functions ..
</span>      INTEGER            <a name="ILAENV.102"></a><a href="ilaenv.f.html#ILAENV.1">ILAENV</a>
      REAL               SNRM2
      EXTERNAL           <a name="ILAENV.104"></a><a href="ilaenv.f.html#ILAENV.1">ILAENV</a>, SNRM2
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Intrinsic Functions ..
</span>      INTRINSIC          INT, MAX, MIN
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Executable Statements ..
</span><span class="comment">*</span><span class="comment">
</span>      INFO = 0
      LQUERY = ( LWORK.EQ.-1 )
      IF( M.LT.0 ) THEN
         INFO = -1
      ELSE IF( N.LT.0 ) THEN
         INFO = -2
      ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
         INFO = -4
      END IF
<span class="comment">*</span><span class="comment">
</span>      IF( INFO.EQ.0 ) THEN
         MINMN = MIN( M, N )
         IF( MINMN.EQ.0 ) THEN
            IWS = 1
            LWKOPT = 1
         ELSE
            IWS = 3*N + 1
            NB = <a name="ILAENV.128"></a><a href="ilaenv.f.html#ILAENV.1">ILAENV</a>( INB, <span class="string">'<a name="SGEQRF.128"></a><a href="sgeqrf.f.html#SGEQRF.1">SGEQRF</a>'</span>, <span class="string">' '</span>, M, N, -1, -1 )
            LWKOPT = 2*N + ( N + 1 )*NB
         END IF
         WORK( 1 ) = LWKOPT
<span class="comment">*</span><span class="comment">
</span>         IF( ( LWORK.LT.IWS ) .AND. .NOT.LQUERY ) THEN
            INFO = -8
         END IF
      END IF
<span class="comment">*</span><span class="comment">
</span>      IF( INFO.NE.0 ) THEN
         CALL <a name="XERBLA.139"></a><a href="xerbla.f.html#XERBLA.1">XERBLA</a>( <span class="string">'<a name="SGEQP3.139"></a><a href="sgeqp3.f.html#SGEQP3.1">SGEQP3</a>'</span>, -INFO )
         RETURN
      ELSE IF( LQUERY ) THEN
         RETURN
      END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Quick return if possible.
</span><span class="comment">*</span><span class="comment">
</span>      IF( MINMN.EQ.0 ) THEN
         RETURN
      END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Move initial columns up front.
</span><span class="comment">*</span><span class="comment">
</span>      NFXD = 1
      DO 10 J = 1, N
         IF( JPVT( J ).NE.0 ) THEN
            IF( J.NE.NFXD ) THEN
               CALL SSWAP( M, A( 1, J ), 1, A( 1, NFXD ), 1 )
               JPVT( J ) = JPVT( NFXD )
               JPVT( NFXD ) = J
            ELSE
               JPVT( J ) = J
            END IF
            NFXD = NFXD + 1
         ELSE
            JPVT( J ) = J
         END IF
   10 CONTINUE
      NFXD = NFXD - 1
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Factorize fixed columns
</span><span class="comment">*</span><span class="comment">     =======================
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Compute the QR factorization of fixed columns and update
</span><span class="comment">*</span><span class="comment">     remaining columns.
</span><span class="comment">*</span><span class="comment">
</span>      IF( NFXD.GT.0 ) THEN
         NA = MIN( M, NFXD )
<span class="comment">*</span><span class="comment">CC      CALL <a name="SGEQR2.178"></a><a href="sgeqr2.f.html#SGEQR2.1">SGEQR2</a>( M, NA, A, LDA, TAU, WORK, INFO )
</span>         CALL <a name="SGEQRF.179"></a><a href="sgeqrf.f.html#SGEQRF.1">SGEQRF</a>( M, NA, A, LDA, TAU, WORK, LWORK, INFO )
         IWS = MAX( IWS, INT( WORK( 1 ) ) )
         IF( NA.LT.N ) THEN
<span class="comment">*</span><span class="comment">CC         CALL <a name="SORM2R.182"></a><a href="sorm2r.f.html#SORM2R.1">SORM2R</a>( 'Left', 'Transpose', M, N-NA, NA, A, LDA,
</span><span class="comment">*</span><span class="comment">CC  $                   TAU, A( 1, NA+1 ), LDA, WORK, INFO )
</span>            CALL <a name="SORMQR.184"></a><a href="sormqr.f.html#SORMQR.1">SORMQR</a>( <span class="string">'Left'</span>, <span class="string">'Transpose'</span>, M, N-NA, NA, A, LDA, TAU,
     $                   A( 1, NA+1 ), LDA, WORK, LWORK, INFO )
            IWS = MAX( IWS, INT( WORK( 1 ) ) )
         END IF
      END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Factorize free columns
</span><span class="comment">*</span><span class="comment">     ======================
</span><span class="comment">*</span><span class="comment">
</span>      IF( NFXD.LT.MINMN ) THEN
<span class="comment">*</span><span class="comment">
</span>         SM = M - NFXD
         SN = N - NFXD
         SMINMN = MINMN - NFXD
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Determine the block size.
</span><span class="comment">*</span><span class="comment">
</span>         NB = <a name="ILAENV.201"></a><a href="ilaenv.f.html#ILAENV.1">ILAENV</a>( INB, <span class="string">'<a name="SGEQRF.201"></a><a href="sgeqrf.f.html#SGEQRF.1">SGEQRF</a>'</span>, <span class="string">' '</span>, SM, SN, -1, -1 )
         NBMIN = 2
         NX = 0
<span class="comment">*</span><span class="comment">
</span>         IF( ( NB.GT.1 ) .AND. ( NB.LT.SMINMN ) ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">           Determine when to cross over from blocked to unblocked code.
</span><span class="comment">*</span><span class="comment">
</span>            NX = MAX( 0, <a name="ILAENV.209"></a><a href="ilaenv.f.html#ILAENV.1">ILAENV</a>( IXOVER, <span class="string">'<a name="SGEQRF.209"></a><a href="sgeqrf.f.html#SGEQRF.1">SGEQRF</a>'</span>, <span class="string">' '</span>, SM, SN, -1,
     $           -1 ) )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">
</span>            IF( NX.LT.SMINMN ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">              Determine if workspace is large enough for blocked code.
</span><span class="comment">*</span><span class="comment">
</span>               MINWS = 2*SN + ( SN+1 )*NB
               IWS = MAX( IWS, MINWS )
               IF( LWORK.LT.MINWS ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">                 Not enough workspace to use optimal NB: Reduce NB and
</span><span class="comment">*</span><span class="comment">                 determine the minimum value of NB.
</span><span class="comment">*</span><span class="comment">
</span>                  NB = ( LWORK-2*SN ) / ( SN+1 )
                  NBMIN = MAX( 2, <a name="ILAENV.225"></a><a href="ilaenv.f.html#ILAENV.1">ILAENV</a>( INBMIN, <span class="string">'<a name="SGEQRF.225"></a><a href="sgeqrf.f.html#SGEQRF.1">SGEQRF</a>'</span>, <span class="string">' '</span>, SM, SN,
     $                    -1, -1 ) )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">
</span>               END IF
            END IF
         END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Initialize partial column norms. The first N elements of work
</span><span class="comment">*</span><span class="comment">        store the exact column norms.
</span><span class="comment">*</span><span class="comment">
</span>         DO 20 J = NFXD + 1, N
            WORK( J ) = SNRM2( SM, A( NFXD+1, J ), 1 )
            WORK( N+J ) = WORK( J )
   20    CONTINUE
<span class="comment">*</span><span class="comment">
</span>         IF( ( NB.GE.NBMIN ) .AND. ( NB.LT.SMINMN ) .AND.
     $       ( NX.LT.SMINMN ) ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">           Use blocked code initially.
</span><span class="comment">*</span><span class="comment">
</span>            J = NFXD + 1
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">           Compute factorization: while loop.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">
</span>            TOPBMN = MINMN - NX
   30       CONTINUE
            IF( J.LE.TOPBMN ) THEN
               JB = MIN( NB, TOPBMN-J+1 )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">              Factorize JB columns among columns J:N.
</span><span class="comment">*</span><span class="comment">
</span>               CALL <a name="SLAQPS.258"></a><a href="slaqps.f.html#SLAQPS.1">SLAQPS</a>( M, N-J+1, J-1, JB, FJB, A( 1, J ), LDA,
     $                      JPVT( J ), TAU( J ), WORK( J ), WORK( N+J ),
     $                      WORK( 2*N+1 ), WORK( 2*N+JB+1 ), N-J+1 )
<span class="comment">*</span><span class="comment">
</span>               J = J + FJB
               GO TO 30
            END IF
         ELSE
            J = NFXD + 1
         END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Use unblocked code to factor the last or only block.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">
</span>         IF( J.LE.MINMN )
     $      CALL <a name="SLAQP2.273"></a><a href="slaqp2.f.html#SLAQP2.1">SLAQP2</a>( M, N-J+1, J-1, A( 1, J ), LDA, JPVT( J ),
     $                   TAU( J ), WORK( J ), WORK( N+J ),
     $                   WORK( 2*N+1 ) )
<span class="comment">*</span><span class="comment">
</span>      END IF
<span class="comment">*</span><span class="comment">
</span>      WORK( 1 ) = IWS
      RETURN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     End of <a name="SGEQP3.282"></a><a href="sgeqp3.f.html#SGEQP3.1">SGEQP3</a>
</span><span class="comment">*</span><span class="comment">
</span>      END

</pre>

 </body>
</html>
